Repository navigation
Conversation
davidh44
force-pushed
the
hdavidh/common-log-sanitizer
branch
from
November 24, 2026 22:56
af08fc3 to
66e3a91
Compare
dagnir
reviewed
Nov 25, 2026
dagnir
left a comment
Contributor
There was a problem hiding this comment.
Agent pointed out we might want to escape here too; at least for exception, I don't think date is necessary since it's coming from the service
Comment on lines
283
to
294
| public void logBackingOff(Duration backoffDelay) { | ||
| SdkStandardLogger.REQUEST_LOGGER.debug(() -> "Retryable error detected. Will retry in " + | ||
| backoffDelay.toMillis() + "ms. Request attempt number " + | ||
| attemptNumber, lastException); | ||
| } | ||
|
|
||
| public void logAcquireFailureBackingOff(Duration acquireFailureBackoffDelay) { | ||
| SdkStandardLogger.REQUEST_LOGGER.debug(() -> "Unable to acquire sufficient retry quota to retry. Will cease retrying in " | ||
| + acquireFailureBackoffDelay.toMillis() + "ms. Request attempt number " + | ||
| attemptNumber, lastException); | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Do we need to sanitize lastException too?
Contributor
Author
There was a problem hiding this comment.
Good catch, updated to sanitize
| return existing; | ||
| } | ||
|
|
||
| EscapedThrowable result = new EscapedThrowable(describe(throwable)); |
Contributor
There was a problem hiding this comment.
Sanitized logged exceptions get a new type, which could affect existing filters setup by customers. Can we do a short surface API review for this? We should also mention it in the changelog.
Contributor
Author
There was a problem hiding this comment.
Updated changelog. Sure, will do surface API review
dagnir
approved these changes
Nov 25, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
SDK log statements include values from applications, services or the file system, and these values can contain control characters. This change centralizes control-character escaping in
utilsand applies it to those log statements while preserving attached stack traces.#7543 introduced the escaping behavior for S3 Transfer Manager. This change moves that implementation to
software.amazon.awssdk.utils.LogSanitizerso SDK modules use the same rules.Modifications
LogSanitizertoutilsas a protected cross-module utility. Keep its escaping rules unchanged.sanitize(Throwable)for log statements that attach exceptions. It returns safe exceptions unchanged, copies and sanitizes unsafe throwable graphs, and returns a type-identifying fallback if reading a custom throwable fails.EscapedThrowableclass for the copies thatsanitize(Throwable)returns. An exception's message cannot be changed in place, so the logger needs a separate object with escaped messages, stack frames, causes and suppressed exceptions. The class skips capturing its own stack trace, and itstoString()returns the original class name and escaped message.MakeHttpRequestStage,RetryableStageHelper, and the NettyResponseHandler, including requests supplied through customSdkHttpRequestimplementations.isDebugEnabled()orisWarnEnabled(), before each log call that attaches an exception throughsanitize(Throwable). Message escaping already runs inside lazy suppliers, but the exception argument is evaluated eagerly, so the check avoids unnecessary work for disabled log levels.docs/guidelines/logging-guidelines.md.Commit breakdown
Centralize log sanitization in utilsadds the shared utility and moves Transfer Manager to it.Sanitize common log values in corecovers auth, file, metric, app ID and CRT logs.Sanitize HTTP request logscovers SDK core request logs and Netty.Sanitize S3 multipart logscovers S3 multipart and presigned Range logs.Sanitize SQS batch manager logscovers SQS visibility-reset logs.Document log sanitization in logging guidelinesadds the escaping rules to the logging guidelines.Behavior changes
report\n2026.txtfails:Before:
After:
EscapedThrowablecopy, which Log4j2 and Logback render assoftware.amazon.awssdk.utils.LogSanitizer$EscapedThrowable: java.io.IOException: bad\nvalue. Tools that filter or group by exception class seeEscapedThrowable, and subtype fields such asAwsServiceException.statusCode()are not available.Testing
Added unit tests.
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.AI tools
License